FROM golang:latest as builder

MAINTAINER Maki

RUN go env -w GO111MODULE=on \
    && go env -w GOPROXY=https://goproxy.cn,direct \
    && echo export PATH="$PATH:$(go env GOPATH)/bin" >> ~/.bashrc

WORKDIR /go/src/a-grpc-demo

COPY . /go/src/a-grpc-demo

RUN go mod download

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o Server user/main.go \
                                              && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o Client main.go

# 运行阶段指定scratch作为基础镜像
FROM scratch as server

WORKDIR /app

COPY --from=builder /go/src/a-grpc-demo/Server .

CMD ["./Server"]

EXPOSE 3000

# 运行阶段指定scratch作为基础镜像
FROM scratch as client

WORKDIR /app

COPY --from=builder /go/src/a-grpc-demo/Client .

CMD ["./Client"]

EXPOSE 3000